package com.li.suanfa;

import java.util.Arrays;
import java.util.Random;

/**  
* 类说明   
*  
* @author ****  
* @date 2018年4月1日  新建  
*/
public class InsertSort {
	public static final int SIZE = 10;
	public static void main(String[] args) {
		int[] array = new int[SIZE];
		Random random = new Random();
		for(int i = 0;i < SIZE ;i++){
			array[i] = random.nextInt(100);
		}
		
		long time1= System.currentTimeMillis();
		System.out.println(Arrays.toString(array));
		insertSort(array);
		System.out.println(Arrays.toString(array));
		System.out.println(System.currentTimeMillis()-time1);
	}
	
	public static void insertSort(int[] a){
		int j = 0;
		int temp = 0;
		for(int i=1;i<a.length;i++){
			temp = a[i];
			j = i-1;
			while(j>=0 && temp<a[j]){
				a[j+1] = a[j];
				j--;
			}
			a[j+1] = temp;
		}
	}
}
  